package com.ytjj.qmyx.supplychain.service;

import com.ytjj.qmyx.supplychain.common.model.response.ProductBrandResponse;
import com.ytjj.qmyx.supplychain.mapper.ProductBrandMapper;
import com.ytjj.qmyx.supplychain.mapper.entity.YxProductBrand;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@Service
public class ProductBrandService {
    @Resource
    private ProductBrandMapper productBrandMapper;

    public List<ProductBrandResponse> getProductBrandList() {
        Example example = new Example(YxProductBrand.class);
        example.selectProperties("id", "brandName");
        List<YxProductBrand> list = productBrandMapper.selectByExample(example);
        List<ProductBrandResponse> result = new ArrayList<>();
        list.stream().forEach(item -> {
            ProductBrandResponse response = new ProductBrandResponse();
            response.setBrandId(item.getId());
            response.setBrand(item.getBrandName());
            result.add(response);
        });
        return result;
    }
}
